package cn.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.common.*;
import cn.kpi.dao.usualassessment.UserUATPjDao;
import cn.kpi.entity.attendance.AttSummaryEntity;
import cn.kpi.entity.usualassessment.*;
import cn.kpi.service.attendance.IAttTbService;
import cn.kpi.service.usualassessment.*;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.filter.LoginCheck;
import cn.kpi.entity.sys.UserEntity;
import cn.kpi.service.sys.IUserService;

@Controller
@RequestMapping("userusasstemppj")
public class UserUsAssTempPjController extends BaseController {
    @Autowired
    private IUserUATMzpdService iUserUATMzpdService;

    @Autowired
    private IUserUATPjService iUserUATPjService;

    @Autowired
    private IUserUsAssTempService iUserUsAssTempService;

    @Autowired
    private IUsAssTemplateService iUsAssTemplateService;


    @Autowired
    private IAttTbService iAttTbService;

    @Autowired
    private UserUATPjDao userUATPjDao;
    @Autowired
    private IUserService iUserService;

    @Autowired
    private IUserUATZpService iUserUATZpService;
    @Autowired
    IAudioUserService audioUserService;


    @RequestMapping(value = "/user_usasstemp_hp_list")
    public String UserUsassTempHpList(Model model) {
        try {
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int quarter = 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }
            if (quarter == 1) {
                year=year-1;
                quarter=4;
            } else {
                quarter = quarter - 1;
            }
            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);
        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_hp_list";
    }

    @RequestMapping(value = "/user_usasstemp_ld_list")
    public String UserUsassTempLdList(Model model) {
        try {
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int quarter = 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }
            if (quarter == 1) {
                year=year-1;
                quarter=4;
            } else {
                quarter = quarter - 1;
            }

            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);
        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_ld_list";
    }


    @RequestMapping(value = "/useraudio")
    public String UserList(Model model) {
        try {

            List<UserEntity> userlst = iUserService.GetUserListByWhere(" and ldzw!='' ");
            model.addAttribute("userlst", userlst);

        } catch (Exception ex) {

        }

        return "usualassessment/useraudio";
    }

    @RequestMapping(value = "/user_usasstemp_hp_show")
    public String UserUsassTempHpShow(Model model, int year, int quarter, Long userid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);
            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById((userid));
            UserUATPjSummaryEntity sumentity = iUserUATPjService.GetUserUATPjSummary(userid, entityusertemp.getTemplateid(), year, quarter, 0);
            List<UserUATHpDetailEntity> lst = iUserUATPjService.GetUserUATHpDetailList(sumentity.getUsasspjid(), userid);
            model.addAttribute("lst", lst);
            model.addAttribute("sumentity", sumentity);
            model.addAttribute("userentity", userentity);

            UserUATZpSummaryEntity sumentityzp = iUserUATZpService.GetUserUATZpSummary(userid, entityusertemp.getTemplateid(), year, quarter);
            UserUATZpAtt entityatt = new UserUATZpAtt();
            entityatt = iUserUATZpService.GetUserUATZpAtt(sumentityzp.getUsasszpid());

            UserUATZpSummaryEntity zp = iUserUATZpService.GetUserUATZpSummaryForMzpd(userid, year, quarter);
            model.addAttribute("gzyj", zp.getGzyj());
            model.addAttribute("czbz", zp.getCzwt());

            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);
            model.addAttribute("userid", userid);
            model.addAttribute("entityatt", entityatt);
        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_hp_show";
    }


    @RequestMapping(value = "/user_usasstemp_ld_show")
    public String UserUsassTempLdShow(Model model, int year, int quarter, Long userid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);
            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById((userid));
            UserUATPjSummaryEntity sumentity = iUserUATPjService.GetUserUATPjSummary(userid, entityusertemp.getTemplateid(), year, quarter, 1);
            List<UserUATLdDetailEntity> lst = iUserUATPjService.GetUserUATLdDetailList(sumentity.getUsasspjid(), userid);
            model.addAttribute("lst", lst);
            model.addAttribute("sumentity", sumentity);
            model.addAttribute("userentity", userentity);

            if (lst.size() > 0) {
                model.addAttribute("audioName", lst.get(0).getAudioname());
                model.addAttribute("time", lst.get(0).getCreatetime());
            }
            UserUATZpSummaryEntity sumentityzp = iUserUATZpService.GetUserUATZpSummary(userid, entityusertemp.getTemplateid(), year, quarter);
            UserUATZpAtt entityatt = new UserUATZpAtt();
            entityatt = iUserUATZpService.GetUserUATZpAtt(sumentityzp.getUsasszpid());
            model.addAttribute("entityatt", entityatt);
        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_ld_show";
    }

    @RequestMapping(value = "/user_usasstemp_hp_edit")
    public String UserUsassTempHpEdit(Model model) {
        try {
            String whereuser = this.GetLoginUserForUserListWhere();
            List<UserEntity> userlst = iUserService.GetUserListByWhere(whereuser);
            model.addAttribute("userlst", userlst);

//			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById(userlst.get(0).getUserid());
//			List<UsAssTempCreateIndexEntity> lst=iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
//			model.addAttribute("lst", lst);
//			String createids = "";
//			for (int i = 0; i < lst.size(); i++) {
//				UsAssTempCreateIndexEntity entity = lst.get(i);
//				createids+=entity.getCreateid()+",";
//			}
//			model.addAttribute("createids", createids.substring(0, createids.length() - 1));
//			model.addAttribute("entityusertemp", entityusertemp);


        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_hp_edit";
    }


    @RequestMapping(value = "/user_usasstemp_hp_edit_show")
    public String UserUsassTempHpEditShow(Model model, int nf, int quarter, Long userid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);

            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById(userid);
            List<UsAssTempCreateIndexEntity> lst = iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
            model.addAttribute("lst", lst);
            String createids = "";
            for (int i = 0; i < lst.size(); i++) {
                UsAssTempCreateIndexEntity entity = lst.get(i);
                createids += entity.getCreateid() + ",";
            }
            model.addAttribute("createids", createids.substring(0, createids.length() - 1));
            model.addAttribute("entityusertemp", entityusertemp);
            model.addAttribute("nf", nf);
            model.addAttribute("quarter", quarter);
            model.addAttribute("userentity", userentity);


        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_hp_edit_show";
    }


    @RequestMapping(value = "/user_usasstemp_hp_edit_new")
    public String UserUsassTempHpEditNew(Model model, int nf, int quarter, Long userid, Long usasspjid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);
            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById(userid);
            UserUATPjSummaryEntity sumentity = new UserUATPjSummaryEntity();
            if (usasspjid > 0) {
                sumentity = iUserUATPjService.GetUserUATPjSummaryById(usasspjid);
                List<UserUATHpDetailEntity> lst = iUserUATPjService.GetUserUATHpDetailListRowSpan(usasspjid);
                model.addAttribute("lst", lst);
                String createids = "";
                for (int i = 0; i < lst.size(); i++) {
                    UserUATHpDetailEntity entity = lst.get(i);
                    createids += entity.getCreateid() + ",";
                }
                model.addAttribute("createids", createids.substring(0, createids.length() - 1));
            } else {
                List<UsAssTempCreateIndexEntity> lst = iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
                model.addAttribute("lst", lst);
                String createids = "";
                for (int i = 0; i < lst.size(); i++) {
                    UsAssTempCreateIndexEntity entity = lst.get(i);
                    createids += entity.getCreateid() + ",";
                }
                model.addAttribute("createids", createids.substring(0, createids.length() - 1));
            }


            model.addAttribute("entityusertemp", entityusertemp);
            model.addAttribute("nf", nf);
            model.addAttribute("quarter", quarter);
            model.addAttribute("userentity", userentity);


            model.addAttribute("sumentity", sumentity);
            model.addAttribute("usasspjid", usasspjid);


            UserUATZpSummaryEntity sumentityzp = iUserUATZpService.GetUserUATZpSummary(userid, entityusertemp.getTemplateid(), nf, quarter);
            UserUATZpAtt entityatt = new UserUATZpAtt();
            entityatt = iUserUATZpService.GetUserUATZpAtt(sumentityzp.getUsasszpid());
            model.addAttribute("entityatt", entityatt);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "usualassessment/user_usasstemp_hp_edit_new";
    }

    @RequestMapping(value = "/user_usasstemp_ld_edit")
    public String UserUsassTempLdEdit(Model model) {
        try {
            String whereuser = this.GetLoginUserForUserListWhere();
            List<UserEntity> userlst = iUserService.GetUserListByWhere(whereuser);
            model.addAttribute("userlst", userlst);

//			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById(userlst.get(0).getUserid());
//			List<UsAssTempCreateIndexEntity> lst=iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
//			model.addAttribute("lst", lst);
//			String createids = "";
//			for (int i = 0; i < lst.size(); i++) {
//				UsAssTempCreateIndexEntity entity = lst.get(i);
//				createids+=entity.getCreateid()+",";
//			}
//			model.addAttribute("createids", createids.substring(0, createids.length() - 1));
//			model.addAttribute("entityusertemp", entityusertemp);

        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_ld_edit";
    }

    @RequestMapping(value = "/user_usasstemp_ld_edit_show")
    public String UserUsassTempLdEditShow(Model model, int nf, int quarter, Long userid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);

            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById(userid);
            List<UsAssTempCreateIndexEntity> lst = iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
            model.addAttribute("lst", lst);
            String createids = "";
            for (int i = 0; i < lst.size(); i++) {
                UsAssTempCreateIndexEntity entity = lst.get(i);
                createids += entity.getCreateid() + ",";
            }
            model.addAttribute("createids", createids.substring(0, createids.length() - 1));
            model.addAttribute("entityusertemp", entityusertemp);
            model.addAttribute("nf", nf);
            model.addAttribute("quarter", quarter);
            model.addAttribute("userentity", userentity);
        } catch (Exception ex) {

        }
        return "usualassessment/user_usasstemp_ld_edit_show";
    }

    @RequestMapping(value = "/user_usasstemp_ld_edit_new")
    public String UserUsassTempLdEditNew(Model model, int nf, int quarter, Long userid, Long usasspjid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);
            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById(userid);
            UserUATPjSummaryEntity sumentity = new UserUATPjSummaryEntity();
            if (usasspjid > 0) {
                sumentity = iUserUATPjService.GetUserUATPjSummaryById(usasspjid);
                List<UserUATLdDetailEntity> lst = iUserUATPjService.GetUserUATLdDetailListRowSpan(usasspjid);
                model.addAttribute("lst", lst);
                String createids = "";
                for (int i = 0; i < lst.size(); i++) {
                    UserUATLdDetailEntity entity = lst.get(i);
                    createids += entity.getCreateid() + ",";
                }
                model.addAttribute("createids", createids.substring(0, createids.length() - 1));
            } else {
                List<UsAssTempCreateIndexEntity> lst = iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
                model.addAttribute("lst", lst);
                String createids = "";
                for (int i = 0; i < lst.size(); i++) {
                    UsAssTempCreateIndexEntity entity = lst.get(i);
                    createids += entity.getCreateid() + ",";
                }
                model.addAttribute("createids", createids.substring(0, createids.length() - 1));
            }


            model.addAttribute("entityusertemp", entityusertemp);
            model.addAttribute("nf", nf);
            model.addAttribute("quarter", quarter);
            model.addAttribute("userentity", userentity);


            model.addAttribute("sumentity", sumentity);
            model.addAttribute("usasspjid", usasspjid);

            UserUATZpSummaryEntity sumentityzp = iUserUATZpService.GetUserUATZpSummary(userid, entityusertemp.getTemplateid(), nf, quarter);
            UserUATZpAtt entityatt = new UserUATZpAtt();
            entityatt = iUserUATZpService.GetUserUATZpAtt(sumentityzp.getUsasszpid());

            String where = "and audio.userid=" + userid;
            List<UserAudio> userAudioList = audioUserService.getUserAduio(where);
            if (userAudioList.size() > 0) {

                model.addAttribute("audioId", userAudioList.get(0).getAudioId());
                model.addAttribute("audioName", userAudioList.get(0).getAudioName());


            } else {

                model.addAttribute("audioName", this.GetLoginUser().getRealname());
                model.addAttribute(Integer.parseInt(this.GetLoginUser().getUserid() + ""));

            }
            model.addAttribute("entityatt", entityatt);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "usualassessment/user_usasstemp_ld_edit_new";
    }


    @ResponseBody
    @RequestMapping(value = "/add_userusasstemppj")
    public String AddUserUsAssTempPj(HttpServletRequest request, HttpServletResponse response) {

        try {
            String createids = request.getParameter("createids");
            if (createids == null || createids.length() <= 0) {
                return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
            }
            String strtemplateid = request.getParameter("templateid");
            if (strtemplateid == null || strtemplateid.length() <= 0) {
                return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
            }
            String struserid = request.getParameter("userid");
            if (struserid == null || struserid.length() <= 0) {
                return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
            }
            Long usasspjid = Long.parseLong(request.getParameter("usasspjid"));

            Long templateid = Long.parseLong(strtemplateid);
            Long userid = Long.parseLong(struserid);
            UserEntity user = this.GetUserById(userid);//拿到保存用户详细信息
            UserEntity byuser = this.GetLoginUser();


            String stpjtype = request.getParameter("pjtype");
            String strnf = request.getParameter("nf");
            String strquarter = request.getParameter("quarter");
            String stpynr = request.getParameter("pynr");
            String stpjjg = request.getParameter("pjjg");

            String[] createidArr = createids.split(",");
//			Map<Long, Integer> map = new HashMap<Long, Integer>(); 
//			int totalscore=0;
            Map<Long, Float> map = new HashMap<Long, Float>();
            Float totalscore = 0f;
            if (stpjtype.equals("0")) {
                for (int i = 0; i < createidArr.length; i++) {
                    String strhpscore = request.getParameter("hpscore_" + createidArr[i]);
                    //Integer hpscore=Integer.parseInt(strhpscore);
                    Float hpscore = Float.parseFloat(strhpscore);
                    map.put(Long.parseLong(createidArr[i]), hpscore);
                    totalscore += hpscore;
                }
            } else {
                for (int i = 0; i < createidArr.length; i++) {
                    String strldscore = request.getParameter("ldscore_" + createidArr[i]);
                    //Integer ldscore=Integer.parseInt(strldscore);
                    Float ldscore = Float.parseFloat(strldscore);
                    map.put(Long.parseLong(createidArr[i]), ldscore);
                    totalscore += ldscore;
                }
            }


            UserUATPjSummaryEntity entity = new UserUATPjSummaryEntity();
            entity.setPynr(stpynr);
            entity.setQuarter(Integer.parseInt(strquarter));
            entity.setStatus(0);
            entity.setTemplateid(templateid);
            entity.setTotalscore(totalscore);
            entity.setUserid(userid);
            entity.setPjjg(stpjjg);
            entity.setYear(Integer.parseInt(strnf));
            entity.setPjtype(Integer.parseInt(stpjtype));

            //固化开始
            entity.setSzdw(user.getSzdw());
            entity.setSzdwname(user.getOrgname());
            entity.setUserstatus(user.getUserstatus());
            entity.setRsgxszdw(user.getRsgxszdw());
            entity.setRsgxszdwname(user.getRsgxorgname());

            entity.setByuserszdw(byuser.getSzdw());
            entity.setByuserszdwname(byuser.getOrgname());
            entity.setByuseruserstatus(byuser.getUserstatus());
            entity.setByuserrsgxszdw(byuser.getRsgxszdw());
            entity.setByuserrsgxszdwname(byuser.getRsgxorgname());


            //固化结束

            String where = "and audio.userid=" + userid;
            List<UserAudio> userAudioList = audioUserService.getUserAduio(where);
            int audioId = Integer.parseInt(this.GetLoginUserId() + "");
            String audioName = this.GetLoginUser().getRealname();
            if (userAudioList.size() > 0) {

                audioId = userAudioList.get(0).getAudioId();
                audioName = userAudioList.get(0).getAudioName();


            }
            int iResult = 0;
            if (usasspjid > 0) {
                entity.setUsasspjid(usasspjid);
                iResult = iUserUATPjService.UpdateUserUATPj(entity, userid, templateid, map, audioId, audioName);
            } else {
                UserUATPjSummaryEntity sumentity = iUserUATPjService.GetUserUATPjSummary(userid, templateid, entity.getYear(), entity.getQuarter(), entity.getPjtype());
                if (sumentity != null) {
                    return renderStringScript(response, "<script>window.parent.CloseDialog(0,'本季度已提交过数据，请勿重复提交')</script>");
                }
                iResult = iUserUATPjService.InsertUserUATPj(entity, userid, templateid, map, audioId, audioName);
            }


            return renderStringScript(response, "<script>window.parent.CloseDialog(" + iResult + ")</script>");
        } catch (Exception ex) {
            ex.printStackTrace();
            return renderStringScript(response, "<script>window.parent.CloseDialog(0)</script>");
        }
    }


    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_pjlist")
    public LayTable<UserUATPjSummaryEntity> GetPjList(HttpServletRequest request) {

        List<UserUATPjSummaryEntity> lst = null;
        LayTable<UserUATPjSummaryEntity> layTable = new LayTable<UserUATPjSummaryEntity>();
        try {
            String strpjtype = request.getParameter("pjtype");
            String realname = request.getParameter("realname");
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            String where = "";
//			if(year!=null&&year.length()>0){
//				where+=" AND year="+year;
//			}
//            if(quarter!=null&&quarter.length()>0){
//            	where+=" AND quarter="+quarter;
//			}

            int pjtype = Integer.parseInt(strpjtype);

            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));
            int beginrow = (page - 1) * limit;
            int endrow = limit;

            where += this.GetUserListByRole();
            if (realname != null && realname.length() > 0) {
                where += " AND realname LIKE '%" + realname + "%'";
            }

            //取出父级状态
            String status = "2";
            String orgwhere = "";
            if (this.GetOrgListByRole() != "") {
                orgwhere = " AND orgid IN (" + this.GetOrgListByRole() + ")";
            }
            List<Map> list = iUserUATPjService.GetPjOrgSumListByStatustype(orgwhere, year, quarter, "hp");
            String notCountBM = "19,44,45,46,47,48";
            for (Map map : list) {
                if(notCountBM.contains(map.get("orgid").toString())) continue;
                if(map.get("status") == null){
                    status = "";
                    break;//跳出
                }else {
                    if(map.get("status").toString().equals("1")){
                        status = "1";
                        break;//跳出
                    }
                }
            }

            int count = 0;

            //11.1平时考核
            where += " AND userstatus='在职'";

            if (status.equals("2"))//已经有值
            {
                lst = iUserUATPjService.GetOldUserPjListProcess(where, year, quarter, pjtype, beginrow, endrow);
                where += " AND year =" + year + " AND pjtype = " + pjtype + " AND quarter = " + quarter;
                count = iUserUATPjService.GetOldUserPjListProcessCount(where);
            } else {
                lst = iUserUATPjService.GetUserPjListProcess(where, year, quarter, pjtype, beginrow, endrow);
                count = iUserUATPjService.GetUserPjListProcessCount(where);
            }

            for (int i = 0; i < lst.size(); i++) {
                int numr = (page - 1) * limit + (i + 1);
                lst.get(i).setRowNum(numr);
                String realorgName = lst.get(i).getRealorgname();
                if (realorgName == null || realorgName.equals("")) {
                    lst.get(i).setRealorgname(lst.get(i).getOrgname());
                }
            }
            layTable.setCode(0);
            layTable.setCount(count);
            layTable.setData(lst);

        } catch (Exception e) {
            layTable.setCode(500);
        }
        return layTable;
    }

    @ResponseBody
    @RequestMapping(value = "/delete_useruathp")
    public ExceResult DeleteUserUATHp(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            Long usasspjid = Long.parseLong(request.getParameter("usasspjid"));
            Long userid = Long.parseLong(request.getParameter("userid"));
            int iResult = iUserUATPjService.DeleteUATHp(usasspjid, userid);
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/delete_useruatld")
    public ExceResult DeleteUserUATLd(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            Long usasspjid = Long.parseLong(request.getParameter("usasspjid"));
            Long userid = Long.parseLong(request.getParameter("userid"));
            int iResult = iUserUATPjService.DeleteUATLD(usasspjid, userid);
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/get_list_org")
    public GridCommon<Map> GetListOrg(HttpServletRequest request) {
        GridCommon<Map> countlist = new GridCommon<Map>();
        try {
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            String where = " AND orgid IN (" + this.GetOrgListByRole() + ")";

            List<Map> list = iUserUATPjService.GetPjOrgSumList(where, year, quarter);
            //List<Map> list =iUserUATPjService.GetPjOrgSumListByStatustype(where, year, quarter,"hp");

            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(list);
            countlist.setStatus(0);
            countlist.setMsg("");
        } catch (Exception e) {
            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(null);
            countlist.setStatus(1);
            countlist.setMsg("操作成功");
        }
        return countlist;
    }

    @ResponseBody
    @RequestMapping(value = "/export_mzpd")
    public ExceResult ExportMzpd(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {

            UserUATQzEntity qz = iUserUATMzpdService.GetQzByStatus();

            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            Long userid = Long.parseLong(request.getParameter("userid"));

            UserUATMzpdEntity entity = new UserUATMzpdEntity();
            UserEntity user = iUserService.GetUserById(userid);
            UserUATZpSummaryEntity zp = iUserUATZpService.GetUserUATZpSummaryForMzpd(userid, year, quarter);


            entity.setGzyj(zp.getGzyj());
            entity.setCzbz(zp.getCzwt());
            entity.setZpjg(zp.getZpjg());
            UserUATPjSummaryEntity hp = userUATPjDao.GetUserUATPjSummaryForMzpd(userid, year, quarter, 0);

//
            UserUATPjSummaryEntity ld = userUATPjDao.GetUserUATPjSummaryForMzpd(userid, year, quarter, 1);


            entity.setRealname(user.getRealname());
            entity.setZzmm(user.getZzmm());
            entity.setGzdw(user.getOrgname());
            entity.setZw("");
            entity.setCsgz("");
            String zq = "";
            String whereatt = " AND year=" + year + " AND userid=" + userid;
            switch (quarter) {
                case 1:
                    zq = year + "年1月1日-" + year + "年3月31日";
                    whereatt += " AND mouth IN(1,2,3)";
                    break;
                case 2:
                    zq = year + "年4月1日-" + year + "年6月30日";
                    whereatt += " AND mouth IN(4,5,6)";
                    break;
                case 3:
                    zq = year + "年7月1日-" + year + "年9月30日";
                    whereatt += " AND mouth IN(7,8,9)";
                    break;
                case 4:
                    zq = year + "年10月1日-" + year + "年12月31日";
                    whereatt += " AND mouth IN(10,11,12)";
                    break;
            }
            whereatt += " AND status=2";

            AttSummaryEntity att = iAttTbService.GetAttTbSummaryByWhereForMzpd(whereatt);
//
//

            String uatattwhere = " AND userid=" + userid + " AND year=" + year + " AND quarter=" + quarter;
            UserUATZpAtt useruatatt = iUserUATZpService.GetUserUATZpAttByWhere(uatattwhere);

            entity.setKhzq(zq);
            entity.setGzyj(zp.getGzyj());
            entity.setCzbz(zp.getCzwt());
            entity.setZpjg(zp.getZpjg());
            if (att != null) {
                entity.setKqcqts(att.getCqts());
                entity.setKqjbts(att.getJbts());
                entity.setKqxjts(att.getXjts());
                entity.setKqbsjts(att.getBsjts());
                entity.setKqgsycjts(att.getGsycjts());
                entity.setKqcdcc(att.getCdcc());
                entity.setKqztcc(att.getZtcc());
                entity.setKqkgcc(att.getKgcs());

            }

            if (useruatatt != null) {
                entity.setKqcqts(useruatatt.getCqts());
                entity.setKqjbts(useruatatt.getJbts());
                entity.setKqxjts(useruatatt.getNxjts());
                entity.setKqbsjts(useruatatt.getBjts() + useruatatt.getSjts());
                entity.setKqgsycjts(useruatatt.getGsts() + useruatatt.getSyjts());
                entity.setKqcdcc(useruatatt.getCdcc());
                entity.setKqztcc(useruatatt.getZtcc());
                entity.setKqkgcc(useruatatt.getKgcs());

            }

            entity.setHpqz(qz.getHpqz());
            entity.setLdqz(qz.getLdqz());
            //int hpdf=(qz.getHpqz()*hp.getTotalscore())/100;
            Float hpdf = (qz.getHpqz() * hp.getTotalscore()) / (100f);
            entity.setNbhpdf(hpdf);
//                float ldpydf=(qz.getLdqz()*ld.getTotalscore())/100;
//            Float ldpydf = (qz.getLdqz() * ld.getTotalscore()) / (100f);
//            entity.setLdpjdf(ldpydf);
//            entity.setLdpynr(ld.getPynr());
//            entity.setPskhzhdf(hpdf + ldpydf);

            UserUATMzpdEntity eResult = entity;
            Map<String, String> dataMap = new HashMap<String, String>();
            dataMap.put("realname", eResult.getRealname());
            dataMap.put("zzmm", eResult.getZzmm());
            dataMap.put("gzdw", eResult.getGzdw());
            dataMap.put("zw", eResult.getZw());
            dataMap.put("csgz", eResult.getCsgz());
            dataMap.put("khzq", eResult.getKhzq());
            dataMap.put("gzyj", eResult.getGzyj());
            dataMap.put("czbz", eResult.getCzbz());
            dataMap.put("zpjg", eResult.getZpjg());
            dataMap.put("kqbsjts", String.valueOf(eResult.getKqbsjts()));
            dataMap.put("kqcdcc", String.valueOf(eResult.getKqcdcc()));
            dataMap.put("kqcqts", String.valueOf(eResult.getKqcqts()));
            dataMap.put("kqgsycjts", String.valueOf(eResult.getKqgsycjts()));
            dataMap.put("kqjbts", String.valueOf(eResult.getKqjbts()));
            dataMap.put("kqkgcc", String.valueOf(eResult.getKqkgcc()));
            dataMap.put("kqxjts", String.valueOf(eResult.getKqxjts()));
            dataMap.put("kqztcc", String.valueOf(eResult.getKqztcc()));

            dataMap.put("hpqz", String.valueOf(eResult.getHpqz()));
            dataMap.put("nbhpdf", String.valueOf(eResult.getNbhpdf()));
            dataMap.put("ldqz", String.valueOf(eResult.getLdqz()));
            dataMap.put("ldpjdf", "");
            dataMap.put("ldpynr", "");
            dataMap.put("pskhzhdf", "");
            dataMap.put("zzpdjg", eResult.getZzpdjg() == null ? "" : eResult.getZzpdjg());
            dataMap.put("dymzpyjg", eResult.getDymzpyjg() == null ? "" : eResult.getDymzpyjg());


            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

            DocumentHandler doc = new DocumentHandler();
            String fileName = eResult.getRealname() + "_" + sdf.format(new Date()) + ".doc";
            String filePath = ConfigOption.getInstance().getFileurl() + "/" + fileName;
            String tempfilename = "mzpdtemp.xml";
            Boolean bolResult = doc.createDoc(dataMap, filePath, tempfilename);


            if (bolResult) {
                String url = ConfigOption.getInstance().getWeburl() + fileName;
                result.setCode(200);
                result.setResult(1);
                result.setMsg(url);
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
            }
        } catch (Exception ex)

        {
            result.setCode(500);
            result.setResult(0);
            result.setMsg(ex.getMessage());
            ex.printStackTrace();
        }
        return result;
    }


    @ResponseBody
    @RequestMapping(value = "/get_list_org_hp")
    public GridCommon<Map> GetListOrgHp(HttpServletRequest request) {
        GridCommon<Map> countlist = new GridCommon<Map>();
        try {
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            String where = " AND orgid IN (" + this.GetOrgListByRole() + ")";

            //List<Map> list = iUserUATPjService.GetPjOrgSumList(where, year, quarter);
            List<Map> list = iUserUATPjService.GetPjOrgSumListByStatustype(where, year, quarter, "hp");

            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(list);
            countlist.setStatus(0);
            countlist.setMsg("");
        } catch (Exception e) {
            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(null);
            countlist.setStatus(1);
            countlist.setMsg("操作成功");
        }
        return countlist;
    }

    @ResponseBody
    @RequestMapping(value = "/get_list_org_ld")
    public GridCommon<Map> GetListOrgLd(HttpServletRequest request) {
        GridCommon<Map> countlist = new GridCommon<Map>();
        try {
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            String where = " AND orgid IN (" + this.GetOrgListByRole() + ")";

            //List<Map> list = iUserUATPjService.GetPjOrgSumList(where, year, quarter);
            List<Map> list = iUserUATPjService.GetPjOrgSumListByStatustype(where, year, quarter, "ld");

            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(list);
            countlist.setStatus(0);
            countlist.setMsg("");
        } catch (Exception e) {
            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(null);
            countlist.setStatus(1);
            countlist.setMsg("操作成功");
        }
        return countlist;
    }


    @ResponseBody
    @RequestMapping(value = "/update_hp_status")
    public ExceResult UpdateHpStatus(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            Long usasspjid = Long.parseLong(request.getParameter("usasspjid"));
            Long userid = Long.parseLong(request.getParameter("userid"));
            int status = Integer.parseInt(request.getParameter("status"));
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));


            int iResult = iUserUATPjService.UpdateUATHpStatus(usasspjid, userid, status, year, quarter);
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/update_ld_status")
    public ExceResult UpdateLdStatus(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            Long usasspjid = Long.parseLong(request.getParameter("usasspjid"));
            Long userid = Long.parseLong(request.getParameter("userid"));
            int status = Integer.parseInt(request.getParameter("status"));
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));


            int iResult = iUserUATPjService.UpdateUATLdStatus(usasspjid, userid, status, year, quarter);
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
        }
        return result;
    }


    @ResponseBody
    @RequestMapping(value = "/update_hp_status_bm")
    public ExceResult UpdateHpStatusBm(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            Long orgid = Long.parseLong(request.getParameter("orgid"));
            int status = Integer.parseInt(request.getParameter("status"));
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));

            Long orgstatustjid = Long.parseLong(request.getParameter("orgstatustjid"));


//		 int iExit=iUserUATPjService.GetOrgStatusCount(orgid, year, quarter,"hp");
//		 if(iExit>0){
//			 result.setCode(300);
//				result.setResult(0);
//				result.setMsg("该部门已提交");
//				return result;
//		 }


            int iResult = iUserUATPjService.UpdateUATHpStatusBmNew(orgid, status, year, quarter, orgstatustjid, "hp");
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }
        return result;
    }


    @ResponseBody
    @RequestMapping(value = "/update_ld_status_bm")
    public ExceResult UpdateLdStatusBm(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            Long orgid = Long.parseLong(request.getParameter("orgid"));
            int status = Integer.parseInt(request.getParameter("status"));
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));

            Long orgstatustjid = Long.parseLong(request.getParameter("orgstatustjid"));


//		 int iExit=iUserUATPjService.GetOrgStatusCount(orgid, year, quarter,"ld");
//		 if(iExit>0){
//			 result.setCode(300);
//				result.setResult(0);
//				result.setMsg("该部门已提交");
//				return result;
//		 }


            int iResult = iUserUATPjService.UpdateUATLdStatusBmNew(orgid, status, year, quarter, orgstatustjid, "ld");
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }
        return result;
    }


    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_zplist_bm")
    public LayTable<UserUATZpSummaryEntity> GetZpListBm(HttpServletRequest request) {

        List<UserUATZpSummaryEntity> lst = null;
        LayTable<UserUATZpSummaryEntity> layTable = new LayTable<UserUATZpSummaryEntity>();
        try {
            String realname = request.getParameter("realname");
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            String where = "";


            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));
            int beginrow = (page - 1) * limit;
            int endrow = limit;

            where += this.GetUserListByRole();
            if (realname != null && realname.length() > 0) {
                where += " AND realname LIKE '%" + realname + "%'";
            }

            String status = "2";
            int count = 0;
            String orgwhere = "";
            if (this.GetOrgListByRole() != "") {
                orgwhere = " AND orgid IN (" + this.GetOrgListByRole() + ")";
            }
            List<Map> list = iUserUATMzpdService.GetPjOrgSumList(orgwhere, year, quarter);
            String notCountBM = "19,44,45,46,47,48";
            for (Map map : list) {
                if(notCountBM.contains(map.get("orgid").toString())) continue;
                if(map.get("status") == null){
                    status = "";
                    break;//跳出
                }else {
                    if(map.get("status").toString().equals("1")){
                        status = "1";
                        break;//跳出
                    }
                }
            }

            //11.1平时考核
            where += " AND userstatus='在职'";
            if (status.equals("2")) {
                lst = iUserUATZpService.GetOldUserZpListProcess(where, year, quarter, beginrow, endrow);
                where += " AND year = " + year + " AND quarter = " + quarter;
                count = iUserUATZpService.GetOldUserZpListProcessCount(where);
            } else {
                lst = iUserUATZpService.GetUserZpListProcess(where, year, quarter, beginrow, endrow);
                count = iUserUATZpService.GetUserZpListProcessCount(where);
            }

            for (int i = 0; i < lst.size(); i++) {
                int numr = (page - 1) * limit + (i + 1);
                lst.get(i).setRowNum(numr);
                String realorgName = lst.get(i).getRealorgname();
                if (realorgName == null || realorgName.equals("")) {
                    lst.get(i).setRealorgname(lst.get(i).getOrgname());
                }
            }

            layTable.setCode(0);
            layTable.setCount(count);
            layTable.setData(lst);

        } catch (Exception e) {
            layTable.setCode(500);
            e.printStackTrace();
        }
        return layTable;
    }

    @RequestMapping(value = "/user_usasstemp_zp_bm_show")
    public String UserUsassTempZpBmShow(Model model, Long userid, int year, int quarter, Long templateid) {
        try {
            UserEntity userentity = iUserService.GetUserById(userid);
            UserTemplateEntity entityusertemp = iUserUsAssTempService.GetUserUsAssTempById(userid);
            UserUATZpSummaryEntity sumentity = iUserUATZpService.GetUserUATZpSummary(userid, templateid, year, quarter);
            List<UserUATZpDetailEntity> lst = iUserUATZpService.GetUserUATZpDetailList(sumentity.getUsasszpid(), userid);
            model.addAttribute("lst", lst);
            model.addAttribute("sumentity", sumentity);
            model.addAttribute("userentity", userentity);

            UserUATZpAtt entityatt = new UserUATZpAtt();
            entityatt = iUserUATZpService.GetUserUATZpAtt(sumentity.getUsasszpid());
            model.addAttribute("entityatt", entityatt);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "usualassessment/user_usasstemp_zp_bm_show";
    }

    @ResponseBody
    @RequestMapping(value = "/getUserAduio")
    public LayTable<UserAudio> getUserAudio(HttpServletRequest request, HttpServletResponse response) {

        List<UserAudio> lst = new ArrayList<>();
        LayTable<UserAudio> layTable = new LayTable<UserAudio>();
        String strWhere = request.getParameter("where");
        lst = audioUserService.getUserAduio(strWhere);
        layTable.setData(lst);
        return layTable;
    }

    @ResponseBody
    @RequestMapping(value = "/addUserAduio")
    public int addAudio(HttpServletRequest request, HttpServletResponse response) {

        try {

            int userId = Integer.parseInt(request.getParameter("userId"));
            int audioId = Integer.parseInt(request.getParameter("audioId"));
            return audioUserService.addUserAudio(userId, audioId);

        } catch (Exception ex) {

            return 0;

        }
    }

    @ResponseBody
    @RequestMapping(value = "/deleteUserAduio")
    public int deleteAudio(HttpServletRequest request, HttpServletResponse response) {
        try {
            int listid = Integer.parseInt(request.getParameter("listid"));
            return audioUserService.deleteUserAusioById(listid);

        } catch (Exception ex) {

            return 0;

        }


    }


}
